package com.nurese.service;

import com.github.pagehelper.PageHelper;
import com.nurese.dao.OrderDao;
import com.nurese.dao.OrderDao;
import com.nurese.entity.Order;
import com.nurese.entity.Order;
import com.nurese.utils.BeanMapUtils;
import com.nurese.utils.MapParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {
    @Autowired
    private OrderDao orderDao;

    public int create(Order order){
        return orderDao.create(order);
    }
    public int delete(Integer id){
//        Map<String,Object> map=new HashMap<>();
//        map.put("id",id);
//        return orderDao.delete(map);

        return orderDao.delete(MapParameter.getInstance().add("id",id).getMap());
    }

    public int delete(String ids){

        String[] arr=ids.split(",");
        int flag=0;
        for (String s:arr){
            flag=orderDao.delete(MapParameter.getInstance().addId(Integer.parseInt(s)).getMap());
        }
        return flag;
    }
    public int update(Order order){
//        Map<String,Object> map= BeanMapUtils.beanToMapForUpdate(order);
//        return orderDao.update(map);

        return orderDao.update(MapParameter.getInstance()
                .add(BeanMapUtils.beanToMapForUpdate(order))
                .addId(order.getId()).getMap());
    }
    public List<Order> query(Order order){
        System.out.println("++++1:"+BeanMapUtils.beanToMap(order));
        if (order !=null && order.getPage() !=null){
            PageHelper.startPage(order.getPage(),order.getLimit());
        }
        return orderDao.query(BeanMapUtils.beanToMap(order));
    }
    public int count(Order order){
        return orderDao.count(BeanMapUtils.beanToMap(order));
    }
    public Order detail(Integer id){
        return orderDao.detail(MapParameter.getInstance().add("id",id).getMap());
    }
}